<?php
//--- 在用 ----------------------------------------------------//
//作者:欧祖新
//写于:2013-03
//整理:2013-03
//-------------------------------------------------------//




//-------------------------------------------------------//
//名字:in_convert($s)
//功能:数据html格式输入
//作者:
//写于:
//整理:2005-4-1 by liudong
//-------------------------------------------------------//
function In_Convert($s) 
{
  $s=str_replace("|","│",$s);
  $s=str_replace("<","&lt;",$s);
  $s=str_replace(">","&gt;",$s);
  $s=str_replace("\r","",$s);
  $s=str_replace("\t","",$s);
  $s=str_replace("\n","<br>",$s);
  $s=str_replace(" ","&nbsp;",$s);
  return $s;
}
//-------------------------------------------------------//

//-------------------------------------------------------//
//名字:checksql($char)
//功能:检查SQL
//作者:liudong
//写于:2005-4-28
//整理:2005-4-28 by liudong
//-------------------------------------------------------//

function checksql($char)
{ 
  $char=mysql_escape_string($char); 
  $char=addslashes($char); 
  return $char; 
}

//-------------------------------------------------------//
//名字:out_convert($s)
//功能:数据html格式输出
//作者:
//写于:
//整理:2003-4-1 by liudong
//-------------------------------------------------------//
function Out_Convert($s) 
{
  $s=str_replace("│","|",$s);
  $s=str_replace("&lt;","<",$s);
  $s=str_replace("&gt;",">",$s);
  $s=str_replace("","\r",$s);
  $s=str_replace("","\t",$s);
  $s=str_replace("<br>","\n",$s);
  $s=str_replace("&nbsp;"," ",$s);
  return $s;
}
//-------------------------------------------------------//

//-------------------------------------------------------//
//名字:phpbox($txt)
//功能:弹出一个提示框，$txt为要弹出的内容。
//作者:hewei
//写于:2003-03
//整理:2003-03
function PhpBox($txt)
{
  echo "<script language='JavaScript'>alert('".$txt."')</script>";
}
//--------------------------------------------------------//

//-------------------------------------------------------//
//名字:GotoPage($page)
//功能:跳转到页面$page
//作者:欧祖新
//写于:2012-09
//整理:2012-09
function GotoPage($page)
{
  if($page=='h')
    $page="javascript: history.back(1)";
  echo "<script language='JavaScript'>location='".$page."';</script>";
}
//--------------------------------------------------------//

//-------------------------------------------------------//
//名字:checkImgType($image_type,$image_name)
//功能:检查图片格式
//作者:刘东
//写于:2002-10
//整理:2002-10-25
function CheckImgType($image_type,$image_name)
{
  if((strcmp($image_type,"image/jpeg")==0)||(strcmp($image_type,"image/gif")==0)||
	 (strcmp($image_type,"image/pjpeg")==0)||(strcmp($image_type,"image/jpg")==0)||
	 (strcmp($image_type,"image/bmp")==0)||(strcmp($image_type,"image/png")==0))
  {
    switch ($image_type)
    {
      case "image/jpg"   :$imageExt=".jpg";   break;
      case "image/jpeg"  :$imageExt=".jpeg";  break;
      case "image/pjpeg" :$imageExt=".pjpeg"; break;
      case "image/gif"   :$imageExt=".gif";	 break;
      case "image/bmp"   :$imageExt=".bmp";	 break;
      case "image/png"   :$imageExt=".png";	 break;
    }	  
    return $imageExt;
  }
  else
  {  
    $txt=$image_name."文件格式不对，不能上传！";
    $txt.="请选择(.jpg)、(.jpeg)、(.pjpeg)、(.gif)、(.png)、(.bmp)类型的文件。";	  
    phpbox($txt);
    GotoPage("h");
    return "err";
   }
}
//--------------------------------------------------------//


//-------------------------------------------------------//
//名字:UploadFile($Img)
//功能:上传图片,返回上传以后的图片名字
//作者:刘东
//写于:2003-05
//整理:2003-05
function UploadFile($SIMG,$SIMG_type,$SIMG_name,$SPATH)
{
  $replaceimgnm=date("YmdHis");
  $SIMGExt=CheckImgType($SIMG_type,$SIMG_name);
  if($SIMGExt=="err")
  {
    exit;
  } 
  $SIMG_name=ereg_replace(" ","_",$SIMG_name);
  $SIMG_name="$replaceimgnm$SIMGExt";
  $SIMG_disp=ereg_replace("_"," ",$SIMG_name);
  $SIMG_name="$replaceimgnm$SIMGExt";
  $SIMGFinal="$SPATH$SIMG_name";
  copy($SIMG, $SIMGFinal);
  unlink($SIMG);
  chmod("$SPATH$SIMG_name", 0777);
  $SPATHIMG="$SPATH$SIMG_name";
  
  return $SPATHIMG;
}
//--------------------------------------------------------//

//-------------------------------------------------------//
//名字:DelFile($Img)
//功能:删除文件
//作者:刘东
//写于:2003-05
//整理:2003-05
//-------------------------------------------------------//
function DelFile($img)
{
  if(file_exists($img))
  {	  
    unlink($img);
  }
}
//-------------------------------------------------------//

//--------------------------------------------------------//
//名字:getimgsize($oldwidth,$oldheight,$imgwidth,$imgheight)
//功能:在固定框内等比例显示图片的大小(无失真)
//作者:刘东
//写于:2002-10
//整理:2002-10-25
//--------------------------------------------------------//
function GetImgSize($oldwidth,$oldheight,$imgwidth,$imgheight)
{
    //$oldwidth设置的宽度，$oldheight设置的高度，$imgwidth图片的宽度，$imgheight图片的高度；

	//单元格装得能装得进图片，则按图片的真实大小显示；
	if($imgwidth<=$oldwidth&&$imgheight<=$oldheight)
	{
	  $arraysize=array('width'=>$imgwidth,'height'=>$imgheight);
      return $arraysize;
    }
	else
	{
	  $suoxiaowidth=$imgwidth-$oldwidth;
      $suoxiaoheight=$imgheight-$oldheight;
      $suoxiaoheightper=$suoxiaoheight/$imgheight;
      $suoxiaowidthper=$suoxiaowidth/$imgwidth;
	  if($suoxiaoheightper>=$suoxiaowidthper)
	  {
		  //单元格高度为准；
		  $aftersuoxiaowidth=$imgwidth*(1-$suoxiaoheightper);
		  $arraysize=array('width'=>$aftersuoxiaowidth,'height'=>$oldheight);
          return $arraysize;
		}
		else
		{ 
		  //单元格宽度为准；
		  $aftersuoxiaoheight=$imgheight*(1-$suoxiaowidthper);
		  $arraysize=array('width'=>$oldwidth,'height'=>$aftersuoxiaoheight);
		  return $arraysize;
		}
	}
}
//--------------------------------------------------------//


//--------------------------------------------------------//
//名字:PrintImg($spathimg,$simgwidth,$simgheight)
//功能:输出图片
//作者:******
//写于:******
//整理:******
//--------------------------------------------------------//
  
function PrintImg($spathimg,$simgwidth,$simgheight)   
{
  if(file_exists($spathimg))
  {
    $size=GetImageSize($spathimg);
	$simgsize=GetImgSize($simgwidth,$simgheight,$size[0],$size[1]);
	echo "<img src=".$spathimg." width=".$simgsize['width']." height=".$simgsize['height']." border='0'>";
  }
  else
  {
    echo "暂缺图片";
  }
}
//--------------------------------------------------------//

//--------------------------------------------------------//
//名字:csubstr($string,$start,$length)
//功能:中文字符串截取函数(无半个汉字)
//作者:欧祖新
//写于:2013-03
//整理:2013-03
//--------------------------------------------------------//
  
function CSubStr($string,$start,$length)   
{
  $str="";
  $len=$start+$length;
  for($i=$start;$i<$len;$i++)
  {
    if(ord(substr($string,$i,1))>0xa0)
	{   
      $str.=substr($string,$i,2);   
      $i++;   
    }   
    else    
      $str.=substr($string,$i,1);
  } 
  if($len<strlen($string))
  {
     $str.="…";
  }
  return $str;
}



//--------------------------------------------------------//
//名字:changefilename()
//功能:成批将大写文件名改为小写
//作者:程勇
//写于:******
//整理:未整理完毕
//--------------------------------------------------------//
function ChangeFileName()
{
  $handle=opendir('.');
  echo "目录 handle: $handle\n";
  echo "档案:\n";
  while ($file = readdir($handle))
  {
    $file1=strtoupper($file);
    rename($file,$file1);
	echo "$file\n";
  }
 closedir($handle);
  //rename();
  //strtoupper
}



//--------------------------------------------------------//
//名字:listbody()
//功能:显示信息内容；
//作者:欧祖新
//写于:2012-09
//整理:2012-09
//--------------------------------------------------------//
function ListBody($body)
{
  //return nl2br(str_replace(" ","&nbsp; ",htmlspecialchars($body)));
  $tmpStr1 = htmlspecialchars($body);
  $tmpStr1 = ereg_replace(" ","&nbsp;",$tmpStr1);
  $tmpStr1 = ereg_replace(" ","&nbsp;&nbsp;",$tmpStr1);
  $tmpStr1 = ereg_replace("\r\n","<br>",$tmpStr1);
  $tmpStr1 = ereg_replace("\r","<br>",$tmpStr1);
  $tmpStr1 = ereg_replace("\n","<br>",$tmpStr1);
  return $tmpStr1;
}


/*
*
* 名字:CheckId($ID)
* 功能:检查正整数的合法性，返回BOOL
* 作者:欧祖新
* 写于:2013-11-06
* 整理:2013-11-06
*
*/
function CheckId($Id)
{
  return eregi("^[0-9]*[0-9]*$",$Id) && strlen($Id)>0 ;
}

//--------------------------------------------------------//
//名字:isvalidemail($Email) 
//功能:检查电子邮件的合法性
//作者:刘东
//写于:2002-11-1
//整理:2002-11-1
//--------------------------------------------------------//
function IsvalidEmail($Email)
{
  if(!ereg("^[[:alnum:]\_\.]+@([[:alnum:]\_]+\.)+[[:alnum:]][[:alnum:]][[:alnum:]]?$",$Email, $regs))
  { 
    $isvalidemail = false; 
  } 
  else 
  { 
    $isvalidemail = true; 
  }
	
  return $isvalidemail; 
}

//--------------------------------------------------------//

//--------------------------------------------------------//
//名字:newtime()
//功能:根据任意思时间跨度，生成另一时间值
//作者:刘东
//写于:2002-12-1
//整理:未整理
//--------------------------------------------------------//
function NewTime($oneDay,$offN,$offType,$displayType)
{
  //$oneDay="2002-10-24";相对时间
  //$offN=24;跨度量。负数表示以前，正数表示以后
  //$offType="month";跨度类型，可year,month,day,week,minite,second
  //$displayType="Y-m-d";新时间的显示格式
  return date($displayType,strtotime("$offN $offType",strtotime($oneDay)));
}

//--------------------------------------------------------//
//名字: Bc_Round($num,$count)
//功能://四舍五入
//作者:刘东
//写于:2002-12
//整理:2002-12
//--------------------------------------------------------//
function Bc_Round($num,$count)
{   
   list($whole_num,$decimal)=explode(".",strval($num));
   $decimal_string=substr($decimal,0,$count);
   $deleterminant=substr($decimal,$count,1);
   if(substr($decimal,0,1)=='9')
   {
	  $len=strlen($decimal_string);
	  for($i=0;$i<$len;$i++)
	  {
	    if(substr($decimal_string,$i,1=='9'))
	    {
		  $true++;
		}
	  }
	  if($true==$len)
	  {
		$whole_num++;
		return $whole_num;
	  }	
   }	
  
   if($deleterminant>=5)
	 $decimal_string++;
		 
   $denom=pow(10,strlen($decimal_string));
   $decimal_corrected=$decimal_string/$denom;
   $result=$whole_num+$decimal_corrected;
   return ($result);
}
	
//--------------------------------------------------------//
//名字: GetMemberInfo($id)
//功能:取得会员资料,并保存在数组.
//作者:刘东
//写于:2002-12
//整理:2005-05
//--------------------------------------------------------//

function GetMemberInfo($stable,$sfield,$skey)
{
   //取出会员资料；
   global $db; 
   $sql="select * from ".$stable." where ".$sfield."='".$skey."'";
   //echo $membersql;
   $result=$db->query($sql);
   $memberob=$db->fetch_object($result);
   $BAS_NO=$memberob->BAS_NO;
   $BAS_NAME=$memberob->BAS_NAME;   
   $COPYRIGHT=$memberob->COPYRIGHT;
   $DOMAIN=$memberob->DOMAIN;
   $T_ID=$memberob->T_ID;
   $EMAIL=$memberob->EMAIL;
   $LOGO_FILE=$memberob->LOGO_FILE;
   $AD_FILE=$memberob->AD_FILE;
   $ZIP=$memberob->ZIP;
   $FAX=$memberob->FAX;
   $ADDRESS=$memberob->ADDRESS;
   $TEL=$memberob->TEL;   
   $memberarray=array('BAS_NO'          =>$BAS_NO,
                      'BAS_NAME'        =>$BAS_NAME,
					  'COPYRIGHT'       =>$COPYRIGHT,
					  'LOGO_FILE'       =>$LOGO_FILE,
					  'AD_FILE'         =>$AD_FILE,
					  'TEMPLATE_ID'     =>$T_ID,
					  'DOMAIN'          =>$DOMAIN,
					  'EMAIL'           =>$EMAIL,
					  'FAX'             =>$FAX,					 
					  'ZIP'             =>$ZIP,
					  'ADDRESS'         =>$ADDRESS,
					  'TEL'             =>$TEL
					);
   $db->free_result($result);
   return $memberarray;
}
//--------------------------------------------------------//


//--------------------------------------------------------//
//名字:NextTime($offN,$oneDay)
//功能:实现算出某个相对时间$oneDay的跨度为$offN的时间
//作者:刘东
//写于:2002-12
//整理:2005-05
//--------------------------------------------------------//
function NextTime($offN,$oneDay)
{
  $offType="day";//跨度类型，可year,month,day,week,minite,second
  $displayType="Y-m-d";//新时间的显示格式
  return date($displayType,strtotime("$offN $offType",strtotime($oneDay)));
}

//--------------------------------------------------------//


//--------------------------------------------------------//
//名字: GetValueByKey($stable,$sfield,$skey,$sfieldvalue)
//功能:从$stable中,提取$sfieldvalue，字段$sfield,关键字$skey,条件是只有一条数据
//例如：根据ID获取名称 
//作者:刘东
//写于:2005-05
//整理:2005-05

function GetValueByKey($stable,$sfield,$skey,$sfieldvalue)
{
  global $db;
  $sql="select * from ".$stable." where ".$sfield."='".$skey."'";  
  $query=$db->query($sql);
  $result=$db->fetch_array($query);  
  return str_replace("*","",$result[$sfieldvalue]);
  $db->free_result($result);
}

function GetValueByKeys($stable,$sfield,$skey,$sfield1,$skey1,$sfieldvalue)
{
  global $db;  
  $sql="select * from ".$stable . " where ". $sfield . "='". $skey . "' and ".$sfield1."='".$skey1."'";    
  $query=$db->query($sql);
  $result=$db->fetch_array($query);
  if($stable=="bas_type")
  {
     return "<a href='".$result["URL"]."?TYPE_ID=".$result["BAS_ID"]."'>".str_replace("*","",$result[$sfieldvalue])."</a>";
  }
  else
  {
     return str_replace("*","",$result[$sfieldvalue]);
  }  
  $db->free_result($result);
}

//--------------------------------------------------------//

//--------------------------------------------------------//
//名字: CountByKey($stable,$sfield,$skey)
//功能:从$stable中,字段$sfield,关键字$skey,检查是否存在有数据
//作者:欧祖新
//写于:2012-09
//整理:2012-09
function CountByKey($stable,$sfield,$skey)
{
  global $db;
  $sql="select * from ".$stable . " where ". $sfield . "='". $skey . "'";
  $query=$db->query($sql);	
  $num=$db->num_rows($query);
  $db->free_result($query);
  If($num>=1)
  {
	return true;
  }   
  else
  {
	return false;
  }	   
}

function CountByKeys($stable,$sfield,$skey,$sfield1,$skey1)
{
  global $db;
  $sql="select * from ".$stable . " where ". $sfield . "='". $skey . "' and ".$sfield1."='".$skey1."'";  
  $query=$db->query($sql);	
  $num=$db->num_rows($query);
  $db->free_result($query);
  If($num>=1)
  {
	return true;
  }   
  else
  {
	return false;
  }	   
}

//--------------------------------------------------------//

//--------------------------------------------------------//
//名字: CountSubKeyByKey($stable,$sfield,$skey)
//功能:从$stable中,字段$sfield,关键字$skey,检查是否存在有下一个编号的数据
//作者:刘东
//写于:2005-05
//整理:2005-05
//--------------------------------------------------------//
function CountSubKeyByKey($stable,$sfield,$skey)
{
  global $db;
  $sql="select * from ".$stable . " where ".$sfield."<>'".$skey."' and  ". $sfield . " like'". $skey . "%'";
  $query=$db->query($sql);	
  $num=$db->num_rows($query);
  $db->free_result($query);
  If($num>=1)
  {
	return true;
  }   
  else
  {
	return false;
  }	   
}

function CountSubKeyByKeys($stable,$sfield,$skey,$sfield1,$skey1)
{
  global $db;
  $sql="select * from ".$stable . " where ".$sfield."<>'".$skey."' and  ". $sfield . " like'". $skey . "%' and ".$sfield1."='".$skey1."'";
  $query=$db->query($sql);	
  $num=$db->num_rows($query);
  $db->free_result($query);
  If($num>=1)
  {
	return true;
  }   
  else
  {
	return false;
  }	   
}

//--------------------------------------------------------//

//--------------------------------------------------------//
//名字:GetBanByKeys($stable,$sfield,$skey,$sfieldvalue)
//功能:根据编号获取导航
//作者:刘东
//写于:2005-05
//整理:2005-05
//--------------------------------------------------------//
function GetBanByKeys($stable,$sfield,$skey,$sfield1,$skey1,$sfieldvalue)
{
   if(strlen($skey)==0)
   {
     return;
   }
   else
   {
     $temp="";
	 for($i=2;$i<=strlen($skey);$i=$i+2)
	 {
	    $subskey=substr($skey,0,$i);
		$temp=$temp.GetValueByKeys($stable,$sfield,$subskey,$sfield1,$skey1,$sfieldvalue)." &gt; ";
	 } 
   }
   $temp=substr($temp,0,strlen($temp)-6);
   return $temp;
}
//--------------------------------------------------------//
//--------------------------------------------------------//
//名字:GetIP()
//功能:获取客户端IP地址 
//作者:欧祖新
//写于:2012-09
//整理:2012-0905
//--------------------------------------------------------//
function GetIP()
{
	$onlineip="";
	if(getenv('HTTP_CLIENT_IP')) $onlineip = getenv('HTTP_CLIENT_IP');
	elseif(getenv('HTTP_X_FORWARDED_FOR')) $onlineip = getenv('HTTP_X_FORWARDED_FOR');
	elseif(getenv('REMOTE_ADDR')) $onlineip = getenv('REMOTE_ADDR');
	else $onlineip = $_SERVER['REMOTE_ADDR']; 
	if($onlineip=="") $onlineip="Unknown";
	return $onlineip;
}
//--------------------------------------------------------//

//--------------------------------------------------------//
//名字:GetOSInfo()
//功能:获取客户端OS
//作者:欧祖新
//写于:2012-09
//整理:2012-09
//--------------------------------------------------------//
function GetOSInfo()
{
	$os="";
	$Agent = $GLOBALS["HTTP_USER_AGENT"];
	if (eregi('win',$Agent) && strpos($Agent, '95')) $os="Win95";
	elseif (eregi('win 9x',$Agent) && strpos($Agent, '4.90')) $os="WinME";
	elseif (eregi('win',$Agent) && ereg('98',$Agent)) $os="Win98";
	elseif (eregi('win',$Agent) && eregi('nt 5\.0',$Agent)) $os="Win2000"; 
	elseif (eregi('win',$Agent) && eregi('nt 5\.1',$Agent)) $os="WinXP"; 
	elseif (eregi('win',$Agent) && eregi('nt',$Agent)) $os="WinNT";
	elseif (eregi('win',$Agent) && ereg('32',$Agent)) $os="Win32";
	elseif (eregi('linux',$Agent)) $os="Linux";
	elseif (eregi('unix',$Agent)) $os="Unix";
	elseif (eregi('sun',$Agent) && eregi('os',$Agent)) $os="SunOS";
	elseif (eregi('ibm',$Agent) && eregi('os',$Agent)) $os="IBM OS/2";
	elseif (eregi('Mac',$Agent) && eregi('PC',$Agent)) $os="Macintosh";
	elseif (eregi('PowerPC',$Agent)) $os="PowerPC";
	elseif (eregi('AIX',$Agent)) $os="AIX";
	elseif (eregi('HPUX',$Agent)) $os="HPUX";
	elseif (eregi('NetBSD',$Agent)) $os="NetBSD";
	elseif (eregi('BSD',$Agent)) $os="BSD";
	elseif (ereg('OSF1',$Agent)) $os="OSF1";
	elseif (ereg('IRIX',$Agent)) $os="IRIX";
	elseif (eregi('FreeBSD',$Agent)) $os="FreeBSD";
	 if ($os=='') $os = "Unknown";
	return $os;
}
//--------------------------------------------------------//

//--------------------------------------------------------//
//名字:GetExplorerInfo()
//功能:获取客户端Explorer信息
//作者:欧祖新
//写于:2012-09
//整理:2012-09
//--------------------------------------------------------//
function GetExplorerInfo()
{
	$os=$_SERVER["HTTP_USER_AGENT"];
	if(strpos($os,"NetCaptor")) $explorer="NetCaptor";
	elseif(strpos($os,"MSIE 6")) $explorer="MSIE 6.x";
	elseif(strpos($os,"MSIE 5")) $explorer="MSIE 5.x";
	elseif(strpos($os,"MSIE 4")) $explorer="MSIE 4.x";
	elseif(strpos($os,"Netscape")) $explorer="Netscape";
	elseif(strpos($os,"Opera")) $explorer="Opera";
	else $explorer="Unknown";
	return $explorer;
}
//--------------------------------------------------------//

//功能:检查带有pattern特征的字符haystack中是否包含字符needle。
//返回结果为BOOL
function InChart($needle,$haystack,$pattern)
{   
   $haystackarray=split($pattern,$haystack);
   return in_array($needle,$haystackarray);
}
//--------------------------------------------------------//
//检查权限 
function CheckRight($needle,$haystack)
{
  //return true;
  return InChart($needle,$haystack,",");
}
//-------------------------------------------------------//

//-------------------------------------------------------//
//功能：更新系统管理员的权限ID串，当系统菜单表的记录数增加或减少时，CALL此函数。
//没有返回结果
function UpdateSysadmPer()
{
  global $db;
  $sql="select CHECK_PERMISSION from bas_menu order by BAS_ID";
  $result=$db->query($sql);
  $tempID="";
  while($row=$db->fetch_array($result))
  {
    $tempID.=$row["CHECK_PERMISSION"].",";
  }
  $db->free_result($result);
  $tempID=substr($tempID,0,strlen($tempID)-1);
  $sql="update per_group set PERMISSION_LIST='".$tempID."' where BAS_ID=1";
  $db->query($sql);
}
//-------------------------------------------------------//

/*
*
* 名字:DownloadFile($file, $file_type, $file_name, $SPATH)
* 功能:上传文件,返回上传以后的文件名字
* 作者:陆广丰
* 写于:2003-05
* 整理:2003-05
*
*/

function DownloadFile($file,$file_type,$file_name,$SPATH)
{
  $replaceimgnm=date("YmdHis");
  $fileExt=CheckFileType($file_type,$file_name);
  if($fileExt=="err")
  {
    exit;
  }
  $file_name=ereg_replace(" ","_",$file_name);
  $file_name="$replaceimgnm$fileExt";
  $file_disp=ereg_replace("_"," ",$file_name);
  $file_name="$replaceimgnm$fileExt";
  $fileFinal="$SPATH$file_name";
  copy($file, $fileFinal);
  unlink($file);
  chmod("$SPATH$file_name", 0777);
  $SPATHFILE="$SPATH$file_name";

  return $SPATHFILE;
}

 // 用正则替换html标记，功能与 DealHtml 相同,来自php手册
  /* $document 应包含一个 HTML 文档。
  *  本例将去掉 HTML 标记，javascript 代码
  *  和空白字符。还会将一些通用的
  *  HTML 实体转换成相应的文本。
  */
function DelHtmlFlag($document)
{

  $search = array ("'<script[^>]*?>.*?</script>'si", // 去掉 javascript
  "'<[\/\!]*?[^<>]*?>'si", // 去掉 HTML 标记
  "'([\r\n])[\s]+'", // 去掉空白字符
  "'&(quot|#34);'i", // 替换 HTML 实体
  "'&(amp|#38);'i",
  "'&(lt|#60);'i",
  "'&(gt|#62);'i",
  "'&(nbsp|#160);'i",
  "'&(iexcl|#161);'i",
  "'&(cent|#162);'i",
  "'&(pound|#163);'i",
  "'&(copy|#169);'i",
  "'&#(\d+);'e"); // 作为 PHP 代码运行

  $replace = array ("",
  "",
  "\\1",
  "\"",
  "&",
  "<",
  ">",
  " ",
  chr(161),
  chr(162),
  chr(163),
  chr(169),
  "chr(\\1)");
  $text = preg_replace ($search, $replace, $document);
  return strip_tags($text);
}


/*
*
* 名字:checkImgType($image_type,$image_name)
* 功能:检查文件格式
* 作者:陆广丰
* 写于:2006-2-27
* 整理:2006-2-27
*
*/
function CheckFileType($file_type, $file_name)
{
  $temp=array('.php','.php3','.php4','.htm','.js','.xml','html');
  $sResourceType=strtolower(strrchr($file_name,"."));
  if (in_array( $sResourceType,$temp))
  
  /*if((strcmp($file_type,"text/html")==0)||(strcmp($file_type,"text/plain")==0)||
  (strrchr($file_name,".")==".php3") || (strrchr($file_name,".")==".php") || (strrchr($file_name,".")==".php4") ||
  (strrchr($file_name,".")==".js") )
  */
  {
	$txt=$file_name."文件格式不对，不能上传！";
    $txt.="不能上传(.php)、(.php3)、(.php4)、(.htm)、(.html)、(.xml)、(.js)类型的文件。";
    phpbox($txt);
    GotoPage("h");
    return "err";
  }
  else
  {
  	$fileExt=strrchr($file_name,".");
    return $fileExt;
  }
}

//格式化HTML字符串
	//输入：HTML字符串
	//输出：字符串
	function Html2Text($html)
	{
		return htmlspecialchars(stripslashes($html));
	}

	//格式化价格字符串
	//输入：价格
	//输出：带有逗号的价格字符串
	function MoneyFormat($price)
	{
		return number_format($price, 2, '.', ',');
	}
?>